﻿using Coldairarrow.Business.Frontstage.Valickets;
using Coldairarrow.Entity.Frontstage.Valickets;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.Frontstage.Valickets
{
    [Route("/Frontstage/Valickets/[controller]/[action]")]
    public class BS_UserPUseLogController : BaseApiController
    {
        #region DI

        public BS_UserPUseLogController(IBS_UserPUseLogBusiness bS_UserPUseLogBus)
        {
            _bS_UserPUseLogBus = bS_UserPUseLogBus;
        }

        IBS_UserPUseLogBusiness _bS_UserPUseLogBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<BS_UserPUseLog>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _bS_UserPUseLogBus.GetDataListAsync(input);
        }

        /// <summary>
        /// 前台——用户获取积分（不调用）
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task UserGetsPoint(GetPointDto input)
        {
            if (input.Code.Equals("450621"))
            {
                await _bS_UserPUseLogBus.UserGetPoint(input);
            }
            else
            {
                throw new BusException("代码错误，录入失败！");
            }
        }

        /// <summary>
        /// 个人中心——获取个人积分总计
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public PointSum GetUSumData()
        {
            return _bS_UserPUseLogBus.GetUSumData();
        }

        /// <summary>
        /// 个人中心——获取个人积分记录列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<GetUPLogDTO>> GetsPDataListAsync(PageInput<ConditionDTO> input)
        {
            return await _bS_UserPUseLogBus.GetPDataListAsync(input);
        }

        [HttpPost]
        public async Task<BS_UserPUseLog> GetTheData(IdInputDTO input)
        {
            return await _bS_UserPUseLogBus.GetTheDataAsync(input.id);
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(BS_UserPUseLog data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _bS_UserPUseLogBus.AddDataAsync(data);
            }
            else
            {
                await _bS_UserPUseLogBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _bS_UserPUseLogBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}